<?php

if (!defined('NV_SYSTEM')) { die ("You can't access this file directly..."); }

$index = 1;
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
$module_name="TimkiemDN";
if (file_exists("".$datafold."/config_".$module_name.".php")) {
	@require_once ("".$datafold."/config_".$module_name.".php");
}
if (defined('_MODTITLE')) $module_title = _MODTITLE;
####################################################################

include("header.php");
$query = stripslashes(check_html($query, nohtml));
if (($query == "") OR ($query == ""._SEARCH."")) {
OpenTable();
echo "<br><form action=\"modules.php?name=TimkiemDN\" method=\"post\">
<table border=\"0\" align=\"center\"><tr><td valign=\"middle\"><input type=\"text\" size=40 name=\"query\" ></td>
<td valign=\"middle\" align=\"left\"><input type=\"submit\" value=\""._NSSEARCH."\"></td>
</tr></table></form>
<div align=\"center\"><br><font class=\"content\" color=\"$textcolor1\">"._NSKEYWORD."</font></div>";
CloseTable();
echo "<br>";
}

else {
     $offset=10;
     if (!isset($min)) $min=0;
     if (!isset($max)) $max=$min+$offset;

OpenTable();
echo ""._NSYOURSEARCH.": <b>$query</b>";
CloseTable();

echo "<br>";
     OpenTable();
     $sql2 = "SELECT custom_title  FROM ".$prefix."_modules WHERE title='Story'";
     $result2 = $db->sql_query($sql2);
     $row = $db->sql_fetchrow($result2);
     $m_title = $row[custom_title];
     echo "<b>"._NSRESULTS.":</b> <b><a href=modules.php?name=Story>$m_title</a></b><br><br>";
     $sql = "select id, title, hometext, bodytext  from $prefix"._truyen." where (title like '%$query%' OR hometext like '%$query%' OR bodytext like '%$query%' OR nguon  like '%$query%' )";
     $result = $db->sql_query($sql);
     $nrows  = $db->sql_numrows($result);
     $x=0;
     if ($nrows>0) {
     while ($row = $db->sql_fetchrow($result)) {
     $id = $row['id'];
     $title = $row['title'];
     $hometext = $row['hometext'];
     $bodytext = $row['bodytext'];
     $text = "$hometext $bodytext";
     $text = stripslashes(check_html($text, nohtml));
     $text = substr($text, 0, 150);
     $furl = "modules.php?name=Story&td=view_article&id=$id";
     echo "<a href=\"$furl\"><b>$title</b></a></font><br><i>$text ...</i><br><br>";
     $x++;
     }
     } else {
     echo "<center><font size=\"2\"><b>"._NOMATCHES."</b></font></center>";
     }

     $prev=$min-$offset;
     if ($prev>=0) {
     print "<br><br><center><a href=\"modules.php?name=TimkiemDN&min=$prev&amp;query=$query\">";
     print "<b>$min "._PREVMATCHES."</b></a></center>";
     }

     $next=$min+$offset;
     if ($x>=9) {
     print "<br><br><center><a href=\"modules.php?name=TimkiemDN&min=$next&amp;query=$query\">";
     print "<b>"._NEXTMATCHES."</b></a></center>";
     }

##############################################################


    $handle=opendir('modules/TimkiemDN/mod');
    while ($file = readdir($handle)) {
    if ($file=='.' || $file=='..') continue;
                $themelist .= "$file ";

    }
    closedir($handle);
    $themelist = explode(" ", $themelist);
    sort($themelist);
    for ($i=0; $i < sizeof($themelist); $i++) {
        if($themelist[$i]!="") {
            $mod_title = str_replace(".php", "", $themelist[$i]);
            $sql3 = "SELECT custom_title  FROM ".$prefix."_modules WHERE title='$mod_title'";
            $result3 = $db->sql_query($sql3);
            $row = $db->sql_fetchrow($result3);
            $m_title = $row[custom_title];
            echo "<hr><b>"._NSRESULTS.":</b> <b><a href=modules.php?name=$mod_title>$m_title</a></b><br><br>";
            include("modules/TimkiemDN/mod/$themelist[$i]");
        }
    }

        CloseTable();
echo "<br>";
OpenTable();
        echo "<form action=\"modules.php?name=$module_name\" method=\"post\">";
        echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">";
        echo "<tr>";
        echo "<td><b>"._NSRETRY."</b></td>";
        echo "<td align=right><input type=text size=30 name=query value=\"$query\">&nbsp;<input type=submit value=\""._NSSEARCH."\"></form>";
        echo "</td></tr><tr><td>&nbsp;</td><td></td></tr>";
        echo "<tr><td><b>"._NSRETRY2."</br></td>";
        echo "<td align=right><b><A href=\"http://www.google.com/search?q=$query\" target=\"_blank\">Google</A></b></td></tr>";
        echo "</table>";

CloseTable();
echo "<br>";

}


include("footer.php");
?>
